<template>
  <DialogTable
    title="选择物料"
    v-model:show="open"
    v-model="selectData"
    :api="requestApi"
    :multiple="true"
    rowKey="code"
    labelKey="name"
    :columns="columns"
    :search="searchParams"
    :showPagination="true"
    @change="selectProd"
  ></DialogTable>
</template>

<script setup name="MatDialog">
import { matFeignSelect } from "@/api/technology/formulation";
import { ref, reactive, toRefs, watch } from "vue";
const open = defineModel("show");
// const selectData = defineModel();
const props = defineProps({
  data: {
    type: [Array, Object],
    default: () => [],
  },
});
const { data: defaultData } = toRefs(props);
// const loading = ref(true);
// const showSearch = ref(true);
// const tableData = ref([]);
const selectData = ref([]);
// const ids = ref([]);
// const single = ref(true);
// const multiple = ref(true);
const requestApi = ref(matFeignSelect);
const data1= reactive({
  form: {},
  columns: [
    {
      label: "物料编号",
      align: "center",
      prop: "code",
    },
    {
      label: "物料名称",
      align: "center",
      prop: "name",
    },
    {
      label: "物料分类",
      align: "center",
      prop: "typeName",
    },
    {
      label: "工厂",
      align: "center",
      prop: "factoryName",
    },
    {
      label: "单位",
      align: "center",
      prop: "measureUnit",
    },
    {
      label: "规格",
      align: "center",
      prop: "packages",
    },
    {
      label: "型号",
      align: "center",
      prop: "model",
    },
    {
      label: "品牌",
      align: "center",
      prop: "brand",
    },
  ],
  searchParams: [
    {
      label: "工厂",
      prop: "factory",
    },
    {
      label: "物料编号",
      prop: "code",
    },

    {
      label: "物料名称",
      prop: "name",
    },
  ],
});
const { form, columns, searchParams } = toRefs(data1);
watch(open, (newValue) => {
  if (newValue) {
    selectData.value = defaultData.value;
  }
});
const emit = defineEmits(["change"]);

function selectProd() {
  emit("change", selectData.value);
}
</script>

<style lang="scss" scoped></style>
